import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

class MyThreadPool {
    private BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(1000);
    //构造方法
    public MyThreadPool(int n) {
        for(int i = 0;i < n;i++) {
            Thread thread = new Thread(() -> {
                while(true) {
                    try {
                        Runnable runnable = queue.take();
                        runnable.run();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }
            });
            thread.start();
        }
    }
    //submit方法
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
}
public class Demo2 {
    public static void main(String[] args) {
        //核心线程,最大线程
    }
    public static void main1(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool = new MyThreadPool(10);
        for(int i = 0;i < 10000;i++) {
            int id = i;
            myThreadPool.submit(new Runnable() {
                public void run() {
                    System.out.println("hello " + id + "," + Thread.currentThread().getName());
                }
            });
        }
    }
}
